package day230519;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/19 14:47
 * 马戏团
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int n = scan.nextInt(); // 人员个数
            Person[] persons = new Person[n]; // 存储人员的基本信息
            for (int i = 0; i < n; i++) {
                int no = scan.nextInt();
                int weight = scan.nextInt();
                int height = scan.nextInt();
                persons[i] = new Person(no, weight, height);
            }
            // 获取最大罗汉数
            int maxHumanCount = getMaxHumanCount(persons, n);
            System.out.println(maxHumanCount);
        }
        scan.close();
    }

    // 动态规划思路, 求最大叠罗汉人数
    private static int getMaxHumanCount(Person[] persons, int n) {
        // 边界处理
        if (n == 0 || n == 1) {
            return n;
        }
        // 按照体重升序, 如果体重相同则按照身高降序(保证不重复计算同一体重的)
        Arrays.sort(persons, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                // 如果体重相同, 则根据身高降序
                if (o1.getWeight() == o2.getWeight()) {
                    return o2.getHeight() - o1.getHeight();
                }
                // 否则, 根据体重升序
                return o1.getWeight() - o2.getWeight();
            }
        });
        // 动态规划过程
        int[] dp = new int[n]; // dp[1] 表示以第 1 个人为罗汉顶的最大叠罗汉数, 与每个人的编号无关
        Arrays.fill(dp, 1); // 初始状态量
        // 叠罗汉问题， 相当于求身高的最长递增子序列的长度
        int ret = 1; // 用于保存最长递增子序列的长度
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (persons[j].getHeight() <= persons[i].getHeight()) {
                    // 符合递增
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            // 更新结果
            ret = Math.max(ret, dp[i]);
        }
        return ret;
    }
}


// 人员类, 用于存储每个人的编号, 体重和身高
class Person {
    private int no; // 编号
    private int weight; // 体重
    private int height; // 身高

    public Person(int no, int weight, int height) {
        this.no = no;
        this.weight = weight;
        this.height = height;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
}
